$(document).ready(function () {
	//findFirstReportPropose();	
	//findUserInfo1();
	findAllRole(rolechooser,"others");//多角色格式如下：var rolechooser = "1001,1002";
	$('#sureZhzrm').click(function () {
		//setEventPlan2Session();
		//alert("fffffffffff");
		//checkEmergency();
		/*
		if(){
			setCookie(ppId,data.proposes.ppId);
		}*/
		var a=$('#tbUserByPCommander1').text();
		var b=$('#tbUserByPViceCommander1').text();
		var c=$('#tbUserByPTeamLeader1').text();
		var d=$('#tbUserDeptByPImplementPlan1').text();
		var e=$('#tbUserDeptByPAssistDept1').text();
		/*
		if(a==""){
			alert("请任命总指挥");
			return;
		} */
		if(b==""){
			alert("请任命指挥长");
			return;
		}
		/*
		if(c==""){
			alert("请任现场查控工作组组长");
			return;
		}
		if(d==""){
			alert("请任命实施应急预案部门");
			return;
		} 
		if (e == ""){
			alert("请任命协助部门");
			return;
		}
		*/
		saveAdmin(a,b,c,d,e);
	});
});

function findFirstReportPropose(){
	//alert("dfgfd");
    var timestamp = Date.parse(new Date());
    $.get("work2/LZMReport_findFirstReportPropose.action?ts=" + timestamp, null, findFirstReportProposeRst);
}

/**
 * 查询事件回调函数
 */
function findFirstReportProposeRst(data){
    if (data.ajaxRst == "success") {
		/*		
		$('#EEventname').text(data.event.EEventname);
        $('#EId').text(data.event.EId);
		$('#tbesEventStatus').text(data.event.tbEventStatus.tbesEventStatus);
		
        $('#EEventCause').val(data.event.EEventCause);
        $('#EEventDesc').val(data.event.EEventDesc);
		
		var ETakeMeasure=data.event.ETakeMeasure;
		if(ETakeMeasure==null)
		ETakeMeasure="暂无";
        $('#ETakeMeasure').val(ETakeMeasure);
        $('#tbEventSource').text(data.event.tbEventSource.esEventSource);*/
		//alert("ggggggggg");
		if(data.users!=null){
			$.each(data.users, function(i, n){
				alert(i);
	        });			
		}
		if(data.userDepts!=null){
			$.each(data.userDepts, function(i, n){
				alert(i);
	        });			
		}
    }
    else {
        alert("服务器异常，请检查后重试 ！");
    }
}


/**
 * 作增加呈批
 */
function saveAdmin(a,b,c,d,e){
	//alert("gggg454545"+b);	
    var EId = getCookie(eventId);
    var url = 'work2/LZMReport_saveAdmin.action';
    var params = {
        'proposes.tbUserByPViceCommander.UId': b,
        'proposes.tbUserByPTeamLeader.UId': c,
        'proposes.tbUserByPCommander.UId': a,
        'proposes.tbEvent.EId': EId,
		//下面是部门
		'proposes.tbUserDeptByPImplementPlan.udId': d,
		'proposes.tbUserDeptByPAssistDept.udId': e
    };
    jQuery.post(url, params, saveAdminRst, 'json');
}

/**
 * 作增加呈批回调函数
 */
function saveAdminRst(data){
	if (data.ajaxRst == "success") {
		//window.location.href="reportTable.jsp?reportTag=succ";
		//checkEmergency();
		//setEventPlan2Session();
		//setCookie(BACK_URL,"event_query_start.jsp");
		window.location.href="/ag/work/operate_rst.jsp";
	}else{
		alert("服务器异常！");
		//setCookie(BACK_URL,"event_query_start.jsp");
		//window.location.href="operate_succ.jsp";
	}	
    //
    //alert(data.ajaxRst);
}

/*
function findUserInfo1(){
    var timestamp = Date.parse(new Date());
    $.get("admin/UserServ_findUserInfo.action?ts=" + timestamp, null, findUserInfoRst1);
}

function findUserInfoRst1(data){
    if (data.ajaxRst == "success") {
        
        var uRoles = new Array(data.tbUser.tbUserRoles.length);
		
		var goo;
		goo=parseInt(data.tbUser.tbUserRoles[0].tbRole.RId);
		if(goo==1002){			
			findAllRole(rolechooser,1004);//多角色格式如下：var rolechooser = "1001,1002";
		}else if(goo==1004){			
			findAllRole(rolechooser,1005);//多角色格式如下：var rolechooser = "1001,1002";
		}else{
			findAllRole(rolechooser,goo+1);//多角色格式如下：var rolechooser = "1001,1002";
		}
    }
}*/
